package com.gopay.common.security.SensitiveInfo.manager.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gopay.common.cipher.constants.EncryptType;
import com.gopay.common.domain.sensitiveInfo.SecurityKeysStorage;
import com.gopay.common.security.SensitiveInfo.dao.SecurityKeysStorageDao;
import com.gopay.common.security.SensitiveInfo.manager.SecurityKeysStorageManager;

/**
 * 
 * @ClassName: SecurityKeysStorageManagerImpl 
 * @Description: SecurityKeysStorageManager的实现类 
 * @author zyt
 * @date 2016年9月2日 下午3:25:53
 */
@Service("securityKeysStorageManager")
public class SecurityKeysStorageManagerImpl implements SecurityKeysStorageManager {
	
	@Resource(name = "securityKeysStorageDao")
	private SecurityKeysStorageDao securityKeysStorageDao;

	@Override
	public SecurityKeysStorage getCurrentKey() {
		String hql = "from SecurityKeysStorage where status=:status";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("status", "01");
		List<SecurityKeysStorage> list = securityKeysStorageDao.findByHql(hql, param);
		if(list.size() > 0){
			return list.get(0);
		}
		return null;
	}

	@Override
	public SecurityKeysStorage getKeyByTypeAndVersion(EncryptType encryptType, String keyVersion) {
		String hql = "from SecurityKeysStorage where encryptType=:encryptType and keyVersion=:keyVersion";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("encryptType", encryptType);
		param.put("keyVersion", keyVersion);
		List<SecurityKeysStorage> list = securityKeysStorageDao.findByHql(hql, param);
		if(list.size() > 0){
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<SecurityKeysStorage> getAllKeys() {
		return securityKeysStorageDao.findAll(SecurityKeysStorage.class);
	}

}
